/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package oneStopShop.Util;

import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import oneStopShop.Beans.Account;
import oneStopShop.Beans.Customer;

/**
 *
 * @author dinesh
 */
public class AccountTableModel extends AbstractTableModel{

    private int colnum = 5;
    private String[] colNames = {"Account ID", "Customer Number", "Created Date", "Credit Limit", "Credit Balance"};
    private ArrayList<String[]> ResultSets;


    public AccountTableModel(List<Account> accountList) {

        ResultSets = new ArrayList<String[]>();


        for (Account acc : accountList) {

            String[] row = {Integer.toString(acc.getAccountId()), Integer.toString(acc.getCustomerNumber()), acc.getCreatedDate().toString(), Float.toString(acc.getCreditLimit()), Float.toString(acc.getCreditBalance())};

            ResultSets.add(row);

        }


    }

    public Object getValueAt(int rowindex, int columnindex) {

        String[] row = ResultSets.get(rowindex);
        return row[columnindex];

    }

    public int getRowCount() {
        return ResultSets.size();
    }

    public int getColumnCount() {
        return colnum;
    }

    public String getColumnName(int param) {

        return colNames[param];
    }
}
